var domainName = "http://192.168.0.101:8080/";

//var domainName = "http://www.guoguojie.com/";

function openUrl(name,type){
	uexWindow.open(name,'0',name+'.html','1','','','0');
}

function backHistory(){
//	uexWindow.back();
//	uexWindow.windowBack(1);
	uexWindow.close(-1);
}


function indexTab(obj,type){
	switch(type){
		case 1:{
			//changeHeader("header_index");
			//zy_con("content", "index_640_content.html", 0, $$("header").offsetHeight);
			uexWindow.open("root",'0','index_640.html','1','','','0');
			break;
		}
			
		case 2:{
			//changeHeader("header_faxian");
			//zy_con("content", "discover_new_content.html", 0, $$("header").offsetHeight);
			uexWindow.open("discover",'0','discover_new.html','1','','','0');
			break;
		}
		case 3:{
			if(window.localStorage){
				var loginName = localStorage.getItem("loginName");
				var loginPwd = localStorage.getItem("loginPwd");
				if(loginName != null && loginName != "" && loginPwd != null && loginPwd != ""){
				//	changeHeader("header_mine");
				//	zy_con("content", "main_content.html", 0, $$("header").offsetHeight);
					uexWindow.open("main",'0','main.html','1','','','0');
				}else{
				//	zy_con("content", "login_content.html", 0, $$("header").offsetHeight);
					//changeHeader("header_login");
					toLogin();
				}
				
			}
			break;
		}
		default:break;
	}
}

function toProDetail(doingId,proId){
	if(window.localStorage){
		localStorage.setItem("doingId",doingId);
		localStorage.setItem("proId",proId);
	}
	uexWindow.open("pro_detail",'0','pro_detail.html','1','','','0');
//	uexWindow.evaluateScript('discover_new','0','location.href="pro_detail.html"');
}


function toLogin(){
	
	uexWindow.open("login",'0','login.html','1','','','0');
}

function login(){
	var login_name = $("#login_name").val();
	var login_pwd = $("#login_pwd").val();
	if(login_name == null || login_name==''){
		uexWindow.alert('请输入邮箱或昵称');
		return ;
	}
	if(login_pwd == null || login_pwd==''){
		uexWindow.alert('请输入密码');
		return ;
	}
	var ajaxId = Math.floor(Math.random() * 100);
	var url = domainName+"mobile/checkMember.htm";
	uexXmlHttpMgr.open(ajaxId, 'POST', url, 20000);
	uexXmlHttpMgr.setPostData(ajaxId, "0", "loginName", login_name);
　　uexXmlHttpMgr.setPostData(ajaxId, "0", "loginPwd", login_pwd);
	uexXmlHttpMgr.onData = function(opcode, status, data){
		if (status == -1){
			alert('网络连接出错，请检查网络!');
		}else if (status == 1){
			var ret = $.parseJSON(data);
			if(ret.success == 'true'){
				if(window.localStorage){
					localStorage.setItem("loginName",login_name);
					localStorage.setItem("loginPwd",login_pwd);
				}
				uexWindow.open("main",'0','main.html','1','','','0');
				
			}else{
				uexWindow.alert('错误','用户名或密码错误','确定');
			}
					
			uexXmlHttpMgr.close(ajaxId);
		}
	}
	uexXmlHttpMgr.send(ajaxId);
}

function logout(){
	if (window.localStorage) {
		localStorage.setItem("loginName","");
		localStorage.setItem("loginPwd","");
	}
	uexWindow.open("root",'0','index_640.html','1','','','0');
}

function toRegister(){
	uexWindow.open("register",'0','register.html','1','','','0');
}

function register(){
	var email = $("#email").val();
	var nickname = $("#nickname").val();
	var password = $("#password").val();
	var rpassword = $("#rpassword").val();
	var sex = $("#sex").val();
	if(email == null || email==''){
		uexWindow.alert('错误','请输入邮箱','确定');
		return ;
	}
	if(nickname == null || nickname==''){
		uexWindow.alert('错误','请输入昵称','确定');
		return ;
	}
	if(password == null || password==''){
		uexWindow.alert('错误','请输入密码','确定');
		return ;
	}
	if(rpassword == null || rpassword=='' || rpassword != password){
		uexWindow.alert('错误','请确认输入密码','确定');
		return ;
	}
	var ajaxId = Math.floor(Math.random() * 100);
	var url = domainName+"mobile/register.htm";
	uexXmlHttpMgr.open(ajaxId, 'POST', url, 20000);
	uexXmlHttpMgr.setPostData(ajaxId, "0", "email", email);
	uexXmlHttpMgr.setPostData(ajaxId, "0", "nickname", nickname);
	uexXmlHttpMgr.setPostData(ajaxId, "0", "password", password);
	uexXmlHttpMgr.setPostData(ajaxId, "0", "nickname", nickname);
	uexXmlHttpMgr.setPostData(ajaxId, "0", "sex", sex);
	uexXmlHttpMgr.onData = function(opcode, status, data){
		if (status == -1){
			alert('网络连接出错，请检查网络!');
		}else if (status == 1){
			var ret = $.parseJSON(data);
			if(ret.success == 'true'){
				if(window.localStorage){
					localStorage.setItem("loginName",nickname);
					localStorage.setItem("loginPwd",password);
				}
				uexWindow.open("main",'0','main.html','1','','','0');
				
			}else{
				uexWindow.alert('错误',ret.msg,'确定');
			}
					
			uexXmlHttpMgr.close(ajaxId);
		}
	}
	uexXmlHttpMgr.send(ajaxId);
}

function totaobaobuy(){
	uexWindow.open("taobaoitem",'0','taobaoitem.html','1','','','0');
}

function toComment(){
	if(checkLogin()){
		uexWindow.open("comment",'0','comment.html','1','','','0');
	}else{
		toLogin();
	}
	
}



function checkLogin(){
	var loginName = localStorage.getItem("loginName");
	var loginPwd = localStorage.getItem("loginPwd");
	return !(loginName == null || loginName == '' || loginPwd == null || loginPwd == '');
}

function comment(){
	if(checkLogin()){
		var content = $("#content").val();
		if(content != null && content != '' && content.length < 140){
			var ajaxId = Math.floor(Math.random() * 100);
			var url = domainName+"mobile/addcomment.htm";
			var doingId = localStorage.getItem("doingId");
			var loginName = localStorage.getItem("loginName");
			var loginPwd = localStorage.getItem("loginPwd");
			uexXmlHttpMgr.open(ajaxId, 'POST', url, 20000);
			uexXmlHttpMgr.setPostData(ajaxId, "0", "loginName", loginName);
            uexXmlHttpMgr.setPostData(ajaxId, "0", "loginPwd", loginPwd);
			uexXmlHttpMgr.setPostData(ajaxId, "0", "commentId", doingId);
			uexXmlHttpMgr.setPostData(ajaxId, "0", "content", content);
			uexXmlHttpMgr.setPostData(ajaxId, "0", "commentIdType", "doingid");
			
			
			uexXmlHttpMgr.onData = function(opcode, status, data){
				if (status == -1){
					uexWindow.alert('网络连接出错，请检查网络!');
				}else if (status == 1){
					var ret = $.parseJSON(data);
				//	var nowTime = (new Date()).getTime();
					if(ret.success == 'true'){
					//	uexWindow.open(nowTime,'0','pro_detail.html','1','','','0');
					//	uexWindow.evaluateScript('pro_detail','0','location.href="pro_detail.html"');
				//		location.href='pro_detail.html';
						uexWindow.evaluateScript('comment','0','backHistory()');
					}else{
						uexWindow.alert('错误',ret.msg,'确定');
					}
							
					uexXmlHttpMgr.close(ajaxId);
				}
			}
			
			uexXmlHttpMgr.send(ajaxId);
		}else{
			uexWindow.alert('错误','评论内容不能为空且不能大于140个字','确定');
		}
		
	}else{
		uexWindow.toast(1, 5, "您还没有登陆", 1000);
	}
	
}

function keepProduct(){
	if(checkLogin()){
		var doingId = localStorage.getItem("doingId");
		if(doingId != null && doingId != ''){
			var ajaxId = Math.floor(Math.random() * 100);
			var url = domainName+"mobile/keep.htm";
			var loginName = localStorage.getItem("loginName");
			var loginPwd = localStorage.getItem("loginPwd");
			uexXmlHttpMgr.open(ajaxId, 'POST', url, 20000);
			uexXmlHttpMgr.setPostData(ajaxId, "0", "loginName", loginName);
            uexXmlHttpMgr.setPostData(ajaxId, "0", "loginPwd", loginPwd);
			uexXmlHttpMgr.setPostData(ajaxId, "0", "doingId", doingId);
			
			
			uexXmlHttpMgr.onData = function(opcode, status, data){
				if (status == -1){
					uexWindow.alert('网络连接出错，请检查网络!');
				}else if (status == 1){
					var ret = $.parseJSON(data);
					if(ret.success == 'true'){
						uexWindow.toast(1, 5, ret.msg, 1000);
					}else{
						uexWindow.toast(1, 5, ret.msg, 1000);
					}
							
					uexXmlHttpMgr.close(ajaxId);
				}
			}
			
			uexXmlHttpMgr.send(ajaxId);
		}else{
			uexWindow.alert('错误','当前商品不存在！','确定');
		}
		
	}else{
		uexWindow.toast(1, 5, "您还没有登陆", 1000);
	}
}

function toPictorial(id){
	if(id != null && id != ""){
		localStorage.setItem("pictorialId",id);
	}
	uexWindow.open('pictorial','0','pictorial.html','1','','','4');
//	uexWindow.evaluateScript('root','0','location.href="pictorial.html"');
}

function toPicDetail(doingId,proId){
	if(window.localStorage){
		localStorage.setItem("doingId",doingId);
		localStorage.setItem("proId",proId);
	}
	uexWindow.open("pic_detail",'0','pic_detail.html','1','','','4');
//	uexWindow.evaluateScript('pictorial','0','location.href="pic_detail.html"');
}





 String.prototype.endWith=function(s){
  if(s==null||s==""||this.length==0||s.length>this.length)
     return false;
  if(this.substring(this.length-s.length)==s)
     return true;
  else
     return false;
  return true;
 }

 String.prototype.startWith=function(s){
  if(s==null||s==""||this.length==0||s.length>this.length)
   return false;
  if(this.substr(0,s.length)==s)
     return true;
  else
     return false;
  return true;
 }
  

 
 function platformBrowser(opId,dataType,data){
 	var plateForm = "";
	if(dataType==2&&data == 0){
		plateForm="IOS";
		uexWidget.loadApp('', '', browserLink);
	}else if(dataType==2&&data == 1){
		plateForm="android";
		uexWidget.loadApp("android.intent.action.VIEW","text/html",browserLink);
	}else if(dataType==2&&data == 2){
		plateForm="Chrome";
		window.location.href=browserLink;
	}else if(dataType==2&&data==3){
		plateForm="symbian";
	}else{
		plateForm="WP7";
	}
	
	
	
}
var browserLink = "";
function openBrowser(link){
	browserLink = link;
	uexWidgetOne.cbGetPlatform = platformBrowser;
	uexWidgetOne.getPlatform();
}



